function formLoad($,form,data) {
    if(data == null || data == undefined || data === '') {
        return;
    }
    if (form == null || form == undefined || form == '') {
        return;
    }
 
    for(var name in data){
        var element = $(form + ' [name=' + name + ']');
 
        if(element == null || element == undefined) {
            continue;
        }
        var attr = $(element).attr("type");
        if(!attr){
            if($(element).get(0)){
                if($(element).get(0).tagName=='SELECT'){
                    attr='select';
                }
            }

        }

        switch (attr){
            case 'hidden':
            case 'text':
          
            case 'number':
                $(element).val(data[name]);
                break;
            case 'checkbox':
			  
                  if(data[name]==null||data[name]==""||data[name]==undefined)break;
                var values=data[name].toString().split(',');
                for(var v in values){
	                 if(v=="remove")continue;
                    var element= $(form + ' [name^=' + name + '][value='+values[v]+']');
                    $(element).attr('checked','checked');
                }
                break;
            case 'radio':
                $(form + ' [name = ' + name + '][value=' + data[name] + ']').next().find("i").click();
                break;
  			case 'select':   
				 $(element).val(data[name]);
	         break;
            default :
                $(element).val(data[name]);
                break;
        }
    }
}


function formClear($,form){
	// console.log( form  )
	  if (form == null || form == undefined || form == '') {
        return;
    }
 $(form + ' input ').val("");
 $(form + ' textarea ').text("");
  $(form)[0].reset()
}

function formReadonly($,form,bool) {
    if(bool){
        $(form).find('input').attr('readonly',true);
        $(form).find('select').attr('disabled',true);
  		$(form).find('textarea').attr('disabled',true);
        $(form).find('button').hide();
    }else{
        $(form).find('input').removeAttr('readonly');
        $(form).find('select').removeAttr('disabled');
		$(form).find('textarea').removeAttr('disabled');
        $(form).find('button').show();
    }
}